//
//  OtherComprehensiveDetailViewController.swift
//  HuaYun
//
//  Created by enghou on 2018/8/24.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

import UIKit

import Charts

class PFormatter: IAxisValueFormatter {
    
    func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        
        switch Int(value) / 10 {
        case 0:
            return "品牌建设计划"
        case 1:
            return "产品推广及广告宣传计划"
        case 2:
            return "重要低值易耗品零星购置"
        case 3:
            return "管理咨询投入计划"
        case 4:
            return "教育培训投入计划"
        case 5:
            return "研发投入计划"
        case 6:
            return "信息化投入计划"
        case 7:
            return "生产辅助大修投入"
        case 8:
            return "固定资产零星购置"
        default:
            
            return "项目收入"
        }
    }
    
}

class OtherComprehensiveDetailViewController: ComprehensiveDetailViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.chartView.dragXEnabled = true
        self.chartView.dragEnabled = true
//        self.chartView.leftAxis.labelPo
        self.chartView.xAxis.valueFormatter = PFormatter()
        self.chartView.xAxis.axisMinimum = -5.0
        
        self.load(with: "Org")
    }
    
    override func path(for name: String) -> String {
        switch name {
        case "GetOrg":
            return GETORG
        case "Org":
            return GETORG
        default:
            return ComprehensivePlanView
        }
        
    }

    override func success(for name: String) -> NetSuccess {
        
        if name == "GetOrg" || name == "Org" {
            return super.success(for: name)
        }
        
        func detail(json: JSON)->Void{
            
            print(json)
            
            if json.contents?["success"]?.bool == true {
                if let data = (json.contents?["data"]?.contents) {
                    
                    let gdzclg = data["gdzclg"]?.double ?? 0.0  / 1000000
                    
                    let glzxxm =  data["glzxxm"]?.double ?? 0.0  / 1000000
                    
                    let jypx = data["jypx"]?.double ?? 0 / 1000000
                    
                    let ppjs = data["ppjs"]?.double ?? 0 / 1000000
                    
                    let scfzdx = data["scfzdx"]?.double ?? 0 / 1000000
                    
                    let sctgxc = data["sctgxc"]?.double ?? 0 / 1000000
                    
                    let xxhjs = data["xxhjs"]?.double ?? 0 / 1000000
                    
                    let yffy = data["yffy"]?.double ?? 0 / 1000000
                    
                    let zydzyh = data["zydzyh"]?.double ?? 0 / 1000000
                    
                    self.setDataCount(values: [ppjs,sctgxc,zydzyh,glzxxm,jypx,yffy,xxhjs,scfzdx,gdzclg])
                }
            }
        }
        
        return detail
        
        
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
